package reflect;

import java.io.File;
import java.lang.reflect.Method;

public class Test3 {
    public static void main(String[] args) throws Exception{
//        File dir = new File(
//                Test3.class.getClassLoader().getResource(
//                        "."
//                ).toURI()
//        );
//        System.out.println(dir);
        File dir =
                new File(Test3.class.getResource(".")
                        .toURI());

        File[] files = dir.listFiles(f -> f.getName().endsWith(".class"));
        for (File file : files) {
            String fileName = file.getName();
            String substring = fileName.substring(0, fileName.indexOf("."));
            Class<?> aClass = Class.forName(Test3.class.getPackage().getName()
                    + "." + substring);
            Object o = aClass.newInstance();
            Method[] declaredMethods = aClass.getDeclaredMethods();
            for (Method method : declaredMethods) {
                if (method.getName().startsWith("s") &&
                method.getParameterCount() == 0){
                    method.setAccessible(true);
                    method.invoke(o);
                }
            }


        }
    }
}
